﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ArduinoAnalyzer.SemanticAnalysis
{
    public class SymbolsTable : List<Symbol>
    {
        private SymbolsTable _parent;
        public SymbolsTable Parent
        {
            get { return _parent; }
            set { _parent = value; }
        }

        public Symbol GetSymbolFromOriginal(string lexeme)
        {
            var symbol = this.FirstOrDefault(s => s.OriginalIdentifier == lexeme);
            if (symbol != null)
                return symbol;

            if (this.Parent == null)
                return null;

            return this.Parent.GetSymbolFromOriginal(lexeme);
        }

        public Symbol GetSymbolFromTemporary(string lexeme)
        {
            var symbol = this.FirstOrDefault(s => s.TemporaryIdentifier == lexeme);
            if (symbol != null)
                return symbol;

            if (this.Parent == null)
                return null;

            return this.Parent.GetSymbolFromTemporary(lexeme);
        }
    }
}
